const Generator = require("yoeman-generator");

module.exports = class extends Generator {
  prompting () {
    // 异步流程控制 返回promise
    return this.prompt ([{
        type: 'input'
        name: 'name'
        message:'Your project name'
        default: this.appname
    }]).then( answers => {
       // answers => { name: 'user input value'}
       this.answers = answers 
    })
}
  writing() {
    // 批量生成 数组循环 数组里面是每个文件的相对路径
    const templates = [
      '.browserslistrc',
      '.editorconfig',
      '.eslintrc.js',
      '.gitignore',
      'bavel.config.js',
      'package.json',
      'README.md',
      'yarn.lock',
      'src/App.vue',
      'src/main.js',
      'src/assets/logo.png',
      'src/components/HelloWorld.vue',
      'src/router/index.js',
      'src/views/About.vue',
      'src/views/Home.vue',
      'public/favicon.ico',
      'public/index.html',
    ]
    templates.forEach(item => {
      this.fs.copyTpl(
        this.templatePath(item), 
        this.destinationPath(item), 
        this.answers)
    })

    
  }
};
